The goal is supposed to return the reverse of an integer as long as it's smaller than 2^31-1(32-bit integers) here is the code:
var reverse = function(x) {
let limit=Math.pow(2,31)-1;
let r=[];
while(x!=0){
r.push(x%10);
x=x%10;
}
let a=0;
let n=0;
while(r){
a=a+r.pop()*Math.pow(1,n);
n++;
}
return a<=limit ? a : 0;
};